<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>15-class的方式设置样式</title>
  <style>
    .box {
      width: 200px;
      height: 200px;
      background-color: cyan;
    }

    .demo {
      font-size: 36px;
      color: yellow;
    }
  </style>
</head>
<body>
  <div id="app">
    <h1>vue的例子</h1>
    <p>{{msg}}</p>
    <div class="box demo">正常类样式</div>
    <hr>
    <div v-bind:class="'box demo'">字符串的方式添加类</div>
    <hr>
    <div :class="{box:true,demo:flag}">对象的方式添加类</div>
    <hr>
    <div :class="['box','demo']">数组的方式添加样式</div>
    <hr>
    <input type="button" value="增加" @click="btnAdd">
    <div :class="arr">数组的方式添加样式</div>
    <hr>
    <div :class="['box',{'demo':true}]">数组和对象一块使用</div>
  </div>
  <script src="../js/vue.js"></script>
  <script>
    Vue.config.productionTip = false; // 关闭生产提示
    const vm = new Vue({
      el: '#app',
      data: {
        msg: 'hello',
        flag: true,
        arr: ['box']
      },
      methods: {
        btnAdd() {
          this.arr.push('demo')
        }
      }
    })
  </script>
</body>
</html>